package smashedapples.managers
{

	import flash.events.EventDispatcher;
	import flash.utils.describeType;
	
	import mx.core.Application;
	import mx.core.Container;
	
	
	public class EventManager
	{	
		/*  
		 the rendezvous object is an event dispatcher where we can subscribe and dispatch events through.
        The dispatcher does not need to know about this point. Only the Listener needs to know where we are going to listen for the event. 
         by default our rendezvous object is Application.application. */
		public static function addEventListener( type:String, listener:Function, rendezvous:EventDispatcher = null, useCapture:Boolean=false, priority:int=1, useWeakReference:Boolean=true ) : void 
     	{     
     		if(rendezvous == null)
           		rendezvous =  (Application.application as Container).systemManager as EventDispatcher;
          		//rendezvous = rendezvous ||  Application.application as EventDispatcher;
          //trace(rendezvous + ".addEventListener(" + type + ")");
          rendezvous.addEventListener( type, listener, useCapture, priority, useWeakReference );
       }
          
          
        public static function dispatchEvent( event:AppEvent, target:EventDispatcher = null ) : void
        {    
            // pass in targets to change where you want the event to originate from.
           if(target == null)
           	target = (Application.application as Container).systemManager as EventDispatcher;
            //target = target || Application.application as EventDispatcher;
            //trace(target + ".dispatchEvent(" + event.type + ")");
            target.dispatchEvent( event );
        }
		
		/* public static function addEventListener( type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false ) : void 
      	{
        	Dispatcher.getInstance().addEventListener( type, listener, useCapture, priority, useWeakReference );
      	}
      	
      	
		public static function dispatchEvent( args:AppEventArgs, bubbles:Boolean = false,cancelable:Boolean = false ) : void
		{	
		
			Dispatcher.getInstance().dispatchEvent( new AppEvent(args.type, args, bubbles, cancelable) );
		}
		 */
	   	
      /* 	public static function hasEventListener( type:String ) : Boolean 
      	{
        	return Dispatcher.getInstance().hasEventListener( type );
      	}
      	
      		
		public static function removeEventListener( type:String, listener:Function, useCapture:Boolean = false ) : void 
      	{
        	Dispatcher.getInstance().removeEventListener( type, listener, useCapture );
      	}
      	
   
      	public static function willTrigger(type:String) : Boolean 
      	{
        	return Dispatcher.getInstance().willTrigger( type );
      	} */
		
	
		
	}
}